//
//  LocalRecordModel.m
//  BDD_TWO
//
//  Created by XTW on 2023/6/9.
//

#import "LocalRecordModel.h"

@implementation LocalRecordModel

- (id)copyWithZone:(NSZone *)zone {
    LocalRecordModel *model = [[[self class] allocWithZone:zone] init];
    model.fileName = self.fileName;
    model.createTime = self.createTime;
    model.nickName = self.nickName;
    model.recordId = self.recordId;
    model.needSaveUrl = self.needSaveUrl;
    model.text = self.text;
    return model;
}

MJCodingImplementation

+ (NSArray *)mj_ignoredCodingPropertyNames {
    return @[@"isSelected", @"isDeleted", @"isPlaying", @"needSaveUrl"];
}

- (void)initCommon {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *dateNow = [NSDate date];
    self.recordId = [NSString stringWithFormat:@"%ld", (long)[dateNow timeIntervalSince1970]];
    NSString *str = [formatter stringFromDate:dateNow];
    self.createTime = str;
}

- (instancetype)initRecord:(NSString *)format {
    self = [super init];
    if (self) {
        [self initCommon];
        self.nickName = [NSString stringWithFormat:@"录音%ld", [UserManger currentLoggedInUser].files.count+1];
        self.fileName = [NSString stringWithFormat:@"%@.%@", self.recordId, format];
    }
    return self;
}

- (instancetype)initImport:(NSString *)name {
    self = [super init];
    if (self) {
        [self initCommon];
        self.nickName = [name stringByDeletingPathExtension];
        self.fileName = [NSString stringWithFormat:@"%@.%@", self.recordId, [name pathExtension]];
    }
    return self;
}

- (instancetype)initMerge {
    self = [super init];
    if (self) {
        [self initCommon];
        self.nickName = [NSString stringWithFormat:@"合并录音%ld", [UserManger currentLoggedInUser].files.count+1];
        self.fileName = [NSString stringWithFormat:@"%@.m4a", self.recordId];
    }
    return self;
}

- (instancetype)initCustom {
    self = [super init];
    if (self) {
        [self initCommon];
    }
    return self;
}
@end
